package com.datang.petstore.controller;

import com.datang.petstore.aop.ForbidAnnotation;
import com.datang.petstore.entity.LoginRecord;
import com.datang.petstore.model.LoginRecordRequest;
import com.datang.petstore.resultpage.Result;
import com.datang.petstore.service.LoginRecordService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-11-01 15:04
 * @notify 用户登录记录api
 * @version 1.0
 */

@RestController
public class LoginRecordController {

    @Autowired
    private LoginRecordService loginRecordService;

    /*
     * @author 顶风少年
     * @date 2019/10/22 16:00
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @param loginRecord
     * @result com.datang.petstore.utils.Result
     * @notify 添加登录记录
     * version 1.0
     */
    @PostMapping(value="login/record")
    @ForbidAnnotation
    public Result addLoginRecord(@RequestBody LoginRecordRequest loginRecordRequest) {
        LoginRecord loginRecord = new LoginRecord();
        BeanUtils.copyProperties(loginRecordRequest, loginRecord);
        loginRecordService.addLoginRecord(loginRecord);
        return Result.ok();
    }
}
